/*jslint maxerr: 50, indent: 4, browser: true */
/*global define */

(function (base, undef) {
    "use strict";

    define("createNamespace", ["mergeModules", "init", "array.length", "array.isArray", "string.split"], function (make) {
        var buri = make.mergeModules(arguments),
            config = {
                "compatability": {}
            };

        function createNamespace(string) {
            var elements,
                element,
                prefix,
                length,
                i = 0;

            if (string && typeof string === "string") {
                elements = buri.string.split(string, ".");
                if (buri.array.isArray(elements)) {
                    prefix = elements[0];
                    length = buri.array.length(elements);
                    while (i < length) {
                        element = elements[i];
                        if (base[element] === undef) {
                            base[element] = {};
                        }

                        base = base[element];
                        i += 1;
                    }
                }
            }

            return base;
        }

        createNamespace.init = function (options) {
            buri.init(config, options);
            buri.array.length.init(config);
            buri.array.isArray.init(config);
            buri.string.split.init(config);
        };

        return {
            "createNamespace": createNamespace
        };
    });
}(window));
